;$(function () {

    layui.use(['form'], function () {
        let form = layui.form;

        $("#basicUpdateName").click(function (obj) {
            let basicName = $("input[name='basicName']").val();
            layer.prompt({
                formType: 0
                , title: '用户名修改'
                , value: basicName
            }, function (value, index) {
                $.post('basicUpdate', {
                    "updateValue": value,
                    "updateObject": "basicName"
                }, function (result) {
                    if (result.code === true) {
                        $("input[name='basicName']").val(result.value);
                        layer.msg("修改成功");
                        layer.close(index);
                    } else {
                        layer.msg(result.msg);
                    }
                });
                form.render();
            });
        });
        $("#basicUpdatePhone").click(function (obj) {
            let basicPhone = $("input[name='basicPhone']").val();
            layer.prompt({
                formType: 0
                , title: '手机号修改'
                , value: basicPhone
            }, function (value, index) {
                $.post('basicUpdate', {
                    "updateValue": value,
                    "updateObject": "basicPhone"
                }, function (result) {
                    if (result.code === true) {
                        $("input[name='basicPhone']").val(result.value);
                        layer.msg("修改成功");
                        layer.close(index);
                    } else {
                        layer.msg(result.msg);
                    }
                });
                form.render();
            });
        });
        $("#basicPwdUpdate").click(function () {
            layer.open({
                type: 1,
                title: "密码修改",
                skin: 'layui-layer-rim',//加边框
                area: ['400px', '280px'],
                content: $("#basicPwdUpdateDiv"),//注意放在<body>最外层
                btn: ['确认', '取消'],
                success: function (index, layero) {
                    $("#basicPwdUpdateDiv").removeClass("layui-hide");
                },
                yes: function (index, layero) {
                    let oldPwd = $("input[name='basicOldPwd']").val();
                    let newPwd = $("input[name='basicNewPwd']").val();
                    if (isEmpty(oldPwd)) {
                        layer.tips('不能为空', $("input[name='basicOldPwd']"));
                    } else if (isEmpty(newPwd)) {
                        layer.tips('不能为空', $("input[name='basicNewPwd']"));
                    }
                    if (!isEmpty(oldPwd) && !isEmpty(newPwd)) {
                        $.ajax({
                            type: 'POST',
                            url: 'updatePassword',
                            data: {
                                "oldPwd": oldPwd,
                                "newPwd": newPwd
                            },
                            dataType: 'JSON',
                            async: false,
                            error: function (data) {
                                layer.msg('稍后再试！');
                            },
                            success: function (data) {
                                if (data.code === true) {
                                    layer.confirm('密码修改成功', {
                                        btn: ['确认'] //按钮
                                    }, function(){
                                        location.href='../user/logout';
                                    });
                                    layer.close(index);
                                } else {
                                    layer.msg(data.msg);
                                }
                            },
                        });
                    }
                },
                btn2: function (index, layero) {
                    layer.close(index);
                },
                end: function () {
                    $("input[name='basicOldPwd']").val("");
                    $("input[name='basicNewPwd']").val("");
                    $("#basicPwdUpdateDiv").addClass("layui-hide");
                }
            });

        });
    });
});
